package com.qifenqian.turbot.module.ui.order.reception

import android.support.v7.widget.LinearLayoutManager
import android.view.View
import com.qifenqian.turbot.R
import com.qifenqian.turbot.base.BaseFragment
import com.qifenqian.turbot.module.adapter.itemdecoration.LinearItemDecoration
import com.qifenqian.turbot.module.adapter.order.OrderReceptionAdapter
import com.qifenqian.turbot.module.contract.OrderContract
import com.qifenqian.turbot.module.entity.response.order.OrderOnlineEntity
import com.qifenqian.turbot.module.entity.response.order.OrderQueueEntity
import com.qifenqian.turbot.module.presenter.OrderPresenter
import kotlinx.android.synthetic.main.fragment_order_reception.view.*

// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

/**
 * @author H
 * @createDate 2019/1/9 17:59
 * @description OrderFragment中的接待
 * @see
 * @since
 */
class ReceptionFragment : BaseFragment<OrderPresenter, OrderContract.View>(), OrderContract.View {

    override fun bindLayoutId(): Int {
        return R.layout.fragment_order_reception
    }

    override fun bindPresenter(): OrderPresenter? {
        return OrderPresenter(activity!!, this)
    }

    private var mOrderNumbers = mutableListOf<String>("A1号(1-2人)", "A8号(6-10人)", "A9号(4-5人)", "A10号(1-2人)", "A11号(1-3人)")
    private var mOrderQueueEntities = mutableListOf<OrderQueueEntity>(
            OrderQueueEntity("A1", 3, "入座3号桌(1-2人)"),
            OrderQueueEntity("A2", 5, "入座5号桌(1-2人)"),
            OrderQueueEntity("A1", 3, "入座3号桌(1-2人)"),
            OrderQueueEntity("A1", 8, "入座8号桌(1-2人)")
                                                                     )
    private var mOrderOnlineEntities = mutableListOf<OrderOnlineEntity>(
            OrderOnlineEntity("7854", 3, 6, "10:52"),
            OrderOnlineEntity("2567", 5, 10, "10:52"),
            OrderOnlineEntity("5541", 3, 8, "10:52"),
            OrderOnlineEntity("2578", 8, 12, "10:52"))
    private var mOrderReceptionNumbersAdapter: OrderReceptionAdapter? = null
    private var mOrderReceptionQueueAdapter: OrderReceptionAdapter? = null
    private var mOrderReceptionOrdersAdapter: OrderReceptionAdapter? = null

    override fun initial(view: View) {
        view.rv_order_reception_numbers.layoutManager = LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false)
        mOrderReceptionNumbersAdapter = OrderReceptionAdapter(OrderReceptionAdapter.ADAPTER_1, R.layout.view_textview, mOrderNumbers)
        view.rv_order_reception_numbers.adapter = mOrderReceptionNumbersAdapter

        view.rv_order_reception_queue.layoutManager = LinearLayoutManager(activity)
        view.rv_order_reception_queue.addItemDecoration(LinearItemDecoration(activity!!))
        mOrderReceptionQueueAdapter = OrderReceptionAdapter(OrderReceptionAdapter.ADAPTER_2, R.layout.item_order_reception_queue, mOrderQueueEntities)
        view.rv_order_reception_queue.adapter = mOrderReceptionQueueAdapter
        mOrderReceptionQueueAdapter!!.setOnChildClickListener(object : OrderReceptionAdapter.OnChildClickListener {
            override fun onClick(position: Int) {
                mOrderQueueEntities.removeAt(position)
                mOrderReceptionQueueAdapter!!.notifyItemRemoved(position)
                if (mOrderQueueEntities.isNullOrEmpty()) {
                    mOrderReceptionQueueAdapter!!.setEmptyView(R.layout.layout_empty, view.rv_order_reception_queue)
                }
            }
        })
        if (mOrderQueueEntities.isNullOrEmpty()) {
            mOrderReceptionQueueAdapter!!.setEmptyView(R.layout.layout_empty, view.rv_order_reception_queue)
        }

        view.rv_order_reception_orders.layoutManager = LinearLayoutManager(activity)
        view.rv_order_reception_orders.addItemDecoration(LinearItemDecoration(activity!!))
        mOrderReceptionOrdersAdapter = OrderReceptionAdapter(OrderReceptionAdapter.ADAPTER_3, R.layout.item_order_reception_orders, mOrderOnlineEntities)
        view.rv_order_reception_orders.adapter = mOrderReceptionOrdersAdapter
        if (mOrderOnlineEntities.isNullOrEmpty()) {
            mOrderReceptionOrdersAdapter!!.setEmptyView(R.layout.layout_empty, view.rv_order_reception_queue)
        }
    }

}

